<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="../Main/topCommon.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="/WEB-INF/CustomTag" prefix="customTag"%>
<script type="text/javascript" src="CourseFileSrcPublic.js"></script>
<link href="../js/jQuery/uploadify.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../js/jQuery/swfobject.js" ></script>
<script type="text/javascript" src="../js/jQuery/jquery.uploadify-3.1.js" ></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	$("#uploadTest").uploadify({
		'auto'             : false,   //是否自动开始
		'buttonClass'      : 'upload_button', //为按钮添加一个类名 
		'buttonCursor'     : 'hand',   //鼠标经过样式
		'buttonImage'      : '../images/upload_icon.gif',
		'buttonText'       : '选择文件',
	  //'debug'            : true,
		'fileObjName'      : 'myFile', 
		'fileSizeLimit'    : '1GB',
		'fileTypeDesc'     : '支持格式：文档，压缩包，图片，Flash，视频，音频',
		'fileTypeExts'     : '*.doc;*.docx;*.txt;*.ppt;*.pptx;*.xls;*.xlsx;*.vsd;*.pot;*.pps;*.rtf;*.wps;*.et;*.dps;*.pdf;*.epub;*.rar;*.zip;*.7z;*.jpg;*.jpeg;*.png;*.gif;*.bmp;*.tiff;*.tga;*.exif;*.fpx;*.swf;*.wmv;*.mpg;*.mpeg;*.avi;*.asf;*.rm;*.rmvb;*.mov;*.mp4;*.mkv;*.flv;*.wma;*.mp3;*.wav;*.mid', 
		'width'     	   : 157,    //按钮图片宽度
		'height'           : 45,    //按钮图片高度
		'method'           : 'post',
		'multi'            : false,   //是否支持多文件上传
		'progressData'     : 'percentage',  //过程显示数据类型
		'queueID'          : 'fileQueue',  //和存放队列的DIV的id一致
		'queueSizeLimit'   : 1,                //队列中同时存在的文件个数限制
		'removeCompleted'  : false, 
		//'requeueErrors'    : true, 
		'uploader'         : '../UploadFile/uploadFile.action',
		'swf'              : '../js/jQuery/uploadify.swf',
		'uploadLimit'      : 1, 
		onUploadSuccess: function (file,data, response) { 
			if(response==true){
				alert("上传成功");
			}else if(response==false){
				alert("上传失败");
			}
			$('#downloadUrl').attr("value",data);
	    },
	    onSelect: function (file) { 

			var oldFileName = file.name;
			var newFileName = oldFileName.substr(0,oldFileName.length-4);
			$('#courseFileName').attr("value",newFileName);
			
			//获取文件扩展名并转换
			getFileType(file.type); 
	    }
	});
				
	//初始化课程列表
	initCourseList();
	courseFileCateIdChange();
				
});




//上传文件
function uploadifyUpload(){ 
 	$('#uploadTest').uploadify('upload','*');
} 

//取消上传文件
function uploadifyClearQueue(){ 
 	$('#uploadTest').uploadify('cancel','*');
} 

//初始化课程列表
function initCourseList(){
	$.post(
		"../AjaxResultData/listAllCourse.action",
		function(data){
			var courseData = eval("("+data.courseData+")");  
			for(var i = 0;i<courseData.length;i++){
				$("#courseId").append("<option value='"+courseData[i].courseId+"'>"+courseData[i].courseName+"</option>");
			}
		},
		"json"
	);
}

//获取文件扩展名并转换
function getFileType(fileType){
	var fileTypeValue = 0;
	switch (fileType) {
		case '.doc':
		case '.docx':
		case '.txt':
		case '.ppt':
		case '.pptx':
		case '.xls':
		case '.xlsx':
		case '.vsd':
		case '.pot':
		case '.pps':
		case '.rtf':
		case '.wps':
		case '.et':
		case '.dps':
		case '.pdf':
		case '.epub':fileTypeValue = "1"; //文档
		break;
		case '.rar':
		case '.zip':
		case '.7z':fileTypeValue = "2"; //压缩包
		break;
		case '.jpg':
		case '.jpeg':
		case '.png':
		case '.gif':
		case '.bmp':
		case '.tiff':
		case '.tga':
		case '.exif':
		case '.fpx': fileTypeValue = "3";//图片
		break;
		case '.swf':fileTypeValue = "4";//Flash
		break;
		case '.wmv':
		case '.mpg':
		case '.mpeg':
		case '.avi':
		case '.asf':
		case '.rm':
		case '.rmvb':
		case '.mov':
		case '.mp4':
		case '.mkv':
		case '.flv':fileTypeValue = "5";//视频
		break;
		case '.wma':
		case '.mp3':
		case '.wav':
		case '.mid':fileTypeValue = "6";//音频
		default: fileTypeValue = "0";//未知
	}
	$('#courseFileType').attr("value",fileTypeValue);
}


//分类ID改变激活事件
function courseFileCateIdChange() {
	$("#courseFileCategoryId").change(function() {
		if ($("#courseFileCategoryId").attr("value") != -1) {
			getCourseFileCateIsPre();
			//$("#courseId").removeClass("required");			
		} else if ($("#courseFileCategoryId").attr("value") == -1) {
			//$("#isPreCourseCate0").attr("checked", false)
			//$("#isPreCourseCate1").attr("checked", false)
			//$("#isPreCourseCateLine").show();
			$("#courseIdLine").show();
			$("#courseIdNull").attr("selected",true);
			//$("#depth").attr("value",1);
			$("#courseId").addClass("required");
		}
	});
}

//获取是否为预置分类并根据其设置当前分类值
function getCourseFileCateIsPre(){
	var courseFileCategoryId = document.getElementById("courseFileCategoryId").value;
	if(courseFileCategoryId!=""){
		$.post(
				"../AjaxResultData/checkParentCateIsPreCoursePublic.action",
				{"courseFileSrcCatePublic.courseFileCateId":courseFileCategoryId},
				function(data){
					var isNotUsedData = eval("("+data.isNotUsedData+")");
					if(isNotUsedData[0].isNotUsed==0){
						//$("#isPreCourseCate0").attr("checked", true);
						//$("#isPreCourseCateLine").hide();
						$("#courseIdLine").hide();
						$("#courseId").attr("value",isNotUsedData[0].cateId);
					}else if(isNotUsedData[0].isNotUsed==1){
						//$("#isPreCourseCate1").attr("checked", true);
						//$("#isPreCourseCateLine").hide();
						$("#courseIdLine").show();
						$("#courseIdNull").attr("selected",true);
					}
					//$("#depth").attr("value",(parseInt(isNotUsedData[0].parentDepth)+1));
					//alert($("#courseId option:selected").attr("value"));
				},
				"json"
		);
	}
}
//-->
</script>
<div class="function_title"><span class="t2"><img src="../images/dqwz.gif">当前位置：添加课程公共文件资源</span></div>
<div class="function_content">
<div class="addItem"><img src="../images/return_icon.png"><a href="listCourseFileSrcPublic.action?intercept=1">返回列表</a></div>

<span class="important_info">注：带*项为必填信息!</span>
<form action="../TeacherCourseFileSrcPublic/insertCourseFileSrcPublic.action" method="post" id="demo" >
<input type="hidden" name="courseFileSrcPublic.author" id="courseFileSrcPublic.author" value="<s:property value="#session.userName" />">
<input type="hidden" name="courseFileSrcPublic.courseFileType" id="courseFileType" value="0"> 
<input type="hidden" name="courseFileSrcPublic.downloadUrl" id="downloadUrl" value=""> 
 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="loginTable">
    <tr>
      <td width="14%" align="right" class="leftBg"><span class="important_info">*</span>文件名称：</td>
      <td width="86%"><input type="text" name="courseFileSrcPublic.courseFileName" id="courseFileName" size="100"></td>
    </tr>
    <tr>
      <td align="right" class="leftBg">文件描述：</td>
      <td><textarea  name="courseFileSrcPublic.courseFileRemark" id="courseFileSrcPublic.majorFileRemark" rows="5" cols="60"></textarea></td>
    </tr>
     
<tr>
      <td align="right" class="leftBg"><span class="important_info">*</span>所属分类：</td>
      <td>
<customTag:treeSelectorCoursePublic courseFileCateId="${courseFileSrcCatePublic.courseFileCateParentId}" type="courseFileSrcPublic" selectName="courseFileCategoryId" notNeedValidation="false" target="false"></customTag:treeSelectorCoursePublic>
</td>
    </tr>
<tr id="courseIdLine">
      <td align="right" class="leftBg"><span class="important_info">*</span>所属课程：</td>
      <td>
<select name="courseFileSrcPublic.courseId" id="courseId">
	<option value="" id="courseIdNull">--未选择--</option>
</select>
	</td>
    </tr>   
    <tr>
      <td align="right" class="leftBg"><span class="important_info">*</span>文件上传：</td>
      <td>
	<div id="fileQueue"></div>
    <input type="file" name="myFile" id="uploadTest" >
    
    <a href="javascript:uploadifyUpload()" style=" font-size:14px;">开始上传</a>
    <a href="javascript:uploadifyClearQueue()" style=" font-size:14px;">取消上传</a>
   
    
    <div class="important_info">注：支持的文件格式：</div>
    <div class="important_info">文档：doc,docx,txt,ppt.pptx,xls,xlsx,vsd.pot,pps,rtf,wps,et,dps,pdf,epub</div>
    <div class="important_info">压缩包：rar,zip,7z</div>
    <div class="important_info">图片：jpg,jpeg,png,gif,bmp,tiff,tga,exif,fpx</div>
    <div class="important_info">Flash：swf</div>
    <div class="important_info">视频：wmv,mpg,mpeg,avi,asf,rm,rmvb,mov,mp4,mkv,flv</div>
    <div class="important_info">音频：wma,mp3,wav,mid</div>
</td>
    </tr>
    <tr>
      <td align="right" class="leftBg">&nbsp;</td>
      <td>
        <input type="submit" name="submit" id="submit" value="提交" class="deal_button">
        <input type="reset" name="reset" id="reset" value="重置" class="deal_button">
      </td>
    </tr>
  </table>
</form>

</div>

<%@ include file="../Main/bottomCommon.jsp"%>